<template>
    <div>
        <el-Card style="margin-bottom:10px">
            <el-form :inline="true" :disabled="!isForbiddenForm" class="demo-form-inline my-category">
                <el-form-item label="一级分类" :inline="true">
                    <el-select v-model="category1Id">
                        <el-option v-for="c1 in categoryStore.category1List" :key="c1.id" :label="c1.name"
                            :value="c1.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="二级分类">
                    <el-select v-model="category2Id">
                        <el-option v-for="c2 in categoryStore.category2List" :key="c2.id" :label="c2.name"
                            :value="c2.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="三级分类">
                    <el-select v-model="category3Id">
                        <el-option v-for="c3 in categoryStore.category3List" :key="c3.id" :label="c3.name"
                            :value="c3.id">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
        </el-Card>
    </div>
</template>
<!-- 
    这个组件因为多个tab都需要使用，所以封装为公共组件
    相对于的数据也会使用多次，这种情况下将数据保存在pinia中,然后引入数据，在页面挂载之后引用pinia内的方法发送请求
    二三级的数据需要id，使用计算属性的完整写法，如果id发生改变则发送请求,每次请求前都需要先将数组清空


 -->
<script lang="ts">
export default {
    name: 'CategorySelector',
    props: {
        isForbiddenForm: {
            type: Boolean
        }
    }
}
</script>
<script lang="ts" setup>
import { onMounted, computed } from 'vue'
import { useGetCategoryStore } from '@/stores/categoryList'
const categoryStore = useGetCategoryStore()


const category1Id = computed<number>({
    get() {
        return categoryStore.category1Id as number
    },
    set(val) {
        console.log(val);

        categoryStore.getCategory2ListData(val)
    }
})

const category2Id = computed<number>({
    get() {
        return categoryStore.category2Id as number
    },
    set(val) {
        categoryStore.getCategory3ListData(val)
    }
})

const category3Id = computed<number>({
    get() {
        return categoryStore.category3Id as number
    },
    set(val) {
        categoryStore.setCategory3Id(val)
    }
})


// 挂载获取一级
onMounted(() => {
    categoryStore.getCategory1ListData()
})
</script>

<style>
</style>